< previous page page_406 next page >

Page 406
What is the function name in the DLL? Because the function uses string parameters, you know that there are two possibilities. If the function only supports Unicode parameters, the name in the DLL will be OpenSCManager. If it supports both ANSI and Unicode parameters, the ANSI entry point will be called OpenSCManagerA, and the Unicode entry pointer will be OpenSCManagerW. Use the DumpInfo utility (on the CD provided with this book) to search the system directory for both OpenSCManager and OpenSCManagerA. You'll find OpenSCManagerA in advapi32.dll.
You can guess that, like most Win32 API functions, this will be a function that returns a Long value. The parameter type returned is an SC_HANDLE, and since you know that almost every handle is a 32-bit Long, you can now be virtually certain that the return type will be a Long. Further proof can be found in the header files provided with the Win32 SDK, where, in file winsvc.h, you'll find the following line:
typedef HANDLE SC_HANDLE;
The machine name and database name are of the LPCTSTR data type. The data type LPCTSTR can be decoded as follows:
LPindicates a long (32-bit) pointer parameter
Cindicates that the parameter is a constant (the data passed to the function will not be changed by the function)
Tindicates that the data is ANSI when called from an ANSI entry point, Unicode when called from a Unicode entry point
STRindicates that the data is a NULL-terminated string

Conclusion: These are pointers to NULL-terminated ANSI strings that are not modified by the function.
The dwDesiredAccess function is easyit's a Long value passed ByVal. The declaration is as follows:
' Service functions
Public Declare Function intOpenSCManager Lib "advapi32" Alias _
"OpenSCManagerA" (ByVal lpMachineName As String, ByVal _
lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
Why did I give the declaration the name intOpenSCManager instead of OpenSCManager? The Alias portion of the declaration uses OpenSCManagerA, the name of the function as it is exported by the DLL. The function name is used

 
< previous page page_406 next page >